#pragma once
#include "MyVector.h"

template<typename T1,typename T2>
class CMyMap
{
	struct CKeyValue
	{
		T1 kKey;
		T2 kValue;

		bool operator==(const CKeyValue& rkOther)
		{
			return (kKey == rkOther.kKey && kValue == rkOther.kValue);
		}
	};

private:
	CMyVector<CKeyValue> m_akData;

public:
	CMyMap()
	{

	}

	CMyMap(const CMyMap& rkMap)
	{
		*this = rkMap;
	}

	~CMyMap()
	{

	}

	CMyMap& operator=(const CMyMap& rkMap)
	{
		m_akData = rkMap.m_akData;		
		return *this;
	}

	bool operator==(const CMyMap& rkMap)
	{		
		return m_akData == rkMap.m_akData;
	}

	CKeyValue& operator[](int iIndex)
	{
		return m_akData[iIndex];
	}

	const CKeyValue& operator[](int iIndex)const
	{
		return m_akData[iIndex];
	}

	T2& operator[](const T1& rKey)
	{		
		T2* pkValue = GetValue(rKey);
		if (pkValue)
		{
			return *pkValue;
		}

		static T2 kValue;

		CKeyValue kData;
		kData.kKey = rKey;
		kData.kValue = kValue;

		m_akData.PushBack(kData);
		return m_akData[GetSize() - 1].kValue;
	}	

	void Clear()
	{
		m_akData.Clear();
	}

	bool IsEmpty()const
	{
		return m_akData.IsEmpty();
	}

	int GetSize()const
	{
		return m_akData.GetSize();
	}
	
	T2* GetValue(const T1& rKey)
	{
		for (int i = 0;i < GetSize();i++)
		{
			if (m_akData[i].kKey == rKey)
			{			
				return &m_akData[i].kValue;
			}
		}

		return NULL;		
	}

	const T2* GetValue(const T1& rKey)const
	{
		return (const_cast<CMyMap*>(this))->GetValue(rKey);
	}

	const bool IsKeyExist(const T1& rkKey)const
	{
		return GetValue(rkKey) != NULL;
	}
};